/*js/login.js 编码为utf-8 */
$(function(){
	
});

function hintErr(id){
	var msg;
	if("username"==id){
		msg='用户名';
	}else{
		msg='密码';
	}
	
	layer.tips(msg+'有误,应为4-10位字母或数字以及下划线组成', '#'+id);
}

function checkName(id){
	var name = $('#username').val();
	var rule = /^\w{4,10}$/;
	if(!rule.test(name)){
		hintErr(id);
		return false;
	}
	return true;
}

function checkPwd(id){
	var password = $('#password').val();
	var rule = /^\w{4,10}$/;
	if(!rule.test(password)){
		hintErr(id);
		return false;
	}
	return true;
}

function loginAction(){
//	console.log("loginAction");
	//获取用户输入的用户名和密码
	var username = $('#username').val();
	var password = $('#password').val();
	var success = checkName()+checkPwd();
	if(success != 2){
		return;
	}
	//data对象中的属性名要与服务器控制器的参数名一致
	var data = {"username":username,"password":password};
	var url = "login.do";
	$.post(
			url,
			data,
			function(result){
				if(result.state == 0 ){
					var deptList = result.data;
					//将json对象转换成json字符串后放入cookie
					
					localStorage.setItem("deptList", JSON.stringify(deptList));
					location.href="selectDept.html";
				}else{
					alertErr(result.message);
				}
	  });
}

function showmess(){
	//iframe窗
	layer.open({
	  type: 2,
	  title: ['用户信息', 'font-size:18px;'],
	  closeBtn: 1, //显示关闭按钮
	  shade: [0],
	  area: ['300px', '420px'],
	  offset: ['9%', '82%'], //右上角弹出
	  shadeClose: true, //开启遮罩关闭
	  time: 10000, //10秒后自动关闭
	  anim: 0,
	  content: ['userMess.html', 'no'], //iframe的url，no代表不显示滚动条
	});
}
